import { ElMessage } from 'element-plus'

// 提示类型
type ElMessageType = 'success' | 'warning' | 'info' | 'error' | undefined

// 函数定义
type ElMessagePopUpParams = (message: string, type: ElMessageType) => void

/**
 * 提示函数
 * */
const ElMessagePopUp: ElMessagePopUpParams = (message, type) => {
    ElMessage({
        showClose: true,
        offset: 5,
        type,
        message
    })
}

const fun = () => 1

fun()
/**
 * 提示约束
 * */
interface ElMessagesParams {
    /** @description 常规灰色 */
    common: (message: string) => void
    /** @description 绿色成功 */
    success: (message: string) => void
    /** @description 橙色警告 */
    warning: (message: string) => void
    /** @description 红色错误 */
    error: (message: string) => void
}

/**
 * @description 消息提示
 *
 * @param {string} message
 *      例: 'Hello World'
 * */
const ElMessages: ElMessagesParams = {
    common(message) {
        ElMessagePopUp(message, undefined)
    },
    success(message) {
        ElMessagePopUp(message, 'success')
    },
    warning(message) {
        ElMessagePopUp(message, 'warning')
    },
    error(message) {
        ElMessagePopUp(message, 'error')
    }
}

export default ElMessages
